package cn.com.lms.business.examRewrite.persistence.repository;

import cn.com.lms.business.examRewrite.persistence.entity.ExerciseQuestionReWrite;
import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ExerciseQuestionReWriteDao extends BaseRepository<ExerciseQuestionReWrite,Long> {

    @Query(nativeQuery = true,value = "SELECT * FROM bnz_exam_exercise_question WHERE exercise_id = ?1")
    List<ExerciseQuestionReWrite> findByExerciseId(Long id);

    /**
     * 通过id(exerciseId)获取ExerciseQuestionReWrite
     * @param id
     * @return
     */
    @Query(nativeQuery = true,value = "SELECT question_id FROM bnz_exam_exercise_question WHERE exercise_id = ?1")
    List<Long> getQuestionIdByExerciseId(Long id);

    /**
     * 通过ExerciseId删除
     * @param result
     * @param id
     */
    @Query(nativeQuery = true,value = "UPDATE bnz_exam_exercise_question SET is_delete = :result WHERE exercise_id in (:id)")
    @Modifying
    void deleteSByExerciseId(@Param("result") boolean result, @Param("id") List<Long> id);
}

